<template >
  <div style="margin-bottom: 20px; text-align: right; color: red">
    * 为必填项
  </div>
  <el-form ref="formRef" :model="formData" label-width="400px">
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="库位编号">
          <el-input
            placeholder="可不填写，自动生成"
            style="width: 350px"
            v-model="formData.warehouseNumber"
            readonly
          ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="仓库">
          <el-select v-model="formData.wHouseId" placeholder="请选择">
            <el-option
              v-for="items in Shopinfo"
              :label="items.wHouseName"
              :value="items.wHouseId"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="仓库名称">
          <el-input
            v-model="formData.warehouseName"
            placeholder="1号仓库"
          ></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="库位类型">
          <el-select v-model="formData.wHouseTypeId" placeholder="请选择">
            <el-option
              v-for="items in wHouseTypeinfo"
              :label="items.wHouseTypeName"
              :value="items.wHouseTypeId"
            />
          </el-select>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :span="12">
        <el-form-item label="是否默认">
          <el-checkbox v-model="formData.defaultnot"></el-checkbox>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="是否禁用">
          <el-checkbox v-model="formData.disable"></el-checkbox>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
  <div style="text-align: center; margin-top: 30px">
    <el-button type="primary" @click="submitForm()">提交</el-button>
    <el-button @click="resetForm">取消</el-button>
  </div>
</template>

<script lang="ts"  setup>
import { ElMessageBox, ElTable, ElMessage } from "element-plus";
import { reactive, onMounted, ref } from "vue";
import axios from "axios";
import { Plus } from "@element-plus/icons-vue";
import { useRouter, useRoute } from "vue-router";
import { KongaUrl } from "@/axios/axiosHelp";
const router = useRouter();
//仓库类型
const Shopinfo = <any>ref([]);
const GetWhouse = () => {
  KongaUrl("/wangcong/api/Whouase/GetWhouse").then((res) => {
    Shopinfo.value = res.data.data;
  });
};
//库位类型
const wHouseTypeinfo = <any>ref([]);
const GetwHouseType = () => {
  KongaUrl("/wangcong/api/Whouase/GetWHouseType").then((res) => {
    wHouseTypeinfo.value = res.data.data;
  });
};

const formRef = ref(null);
const formData = reactive({
  warehouseNumber: "",
  warehouseName: "",
  wHouseId: "",
  wHouseTypeId: "",
  defaultnot: false,
  disable: false,
  isdelete: false,
});

const submitForm = () => {
  KongaUrl.post("/wangcong1/api/WHouase/AddWhouse", formData)
    .then((res) => {
      if (res.data.code == 200) {
        ElMessage.success(res.data.message);
      } else {
        ElMessage.error(res.data.message);
      }
    });
};
const generateTwelveDigitNumber = () => {
  const characters = "0123456789";
  let result = "";
  for (let i = 0; i < 6; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
};
onMounted(() => {
  formData.warehouseNumber = generateTwelveDigitNumber();
  GetWhouse();
  GetwHouseType();
});
</script>

<style scoped>
/* 可以根据需要添加更多自定义样式 */
</style>